<template>
    <el-menu default-active="1" mode="horizontal" @select="handleSelect">
        <el-row type="flex">
            <el-menu-item index="1">处理中心</el-menu-item>
            <el-submenu index="2">
                <template slot="title">我的工作台</template>
                <el-menu-item index="2-1">选项1</el-menu-item>
                <el-menu-item index="2-2">选项2</el-menu-item>
                <el-menu-item index="2-3">选项3</el-menu-item>
                <el-submenu index="2-4">
                    <template slot="title">选项4</template>
                    <el-menu-item index="2-4-1">选项1</el-menu-item>
                    <el-menu-item index="2-4-2">选项2</el-menu-item>
                    <el-menu-item index="2-4-3">选项3</el-menu-item>
                </el-submenu>
            </el-submenu>
            <el-menu-item index="3">消息中心</el-menu-item>
            <el-menu-item index="4">订单管理</el-menu-item>
            <el-col :span="3" :push="12">
                <el-submenu index="5">
                    <template slot="title">
                        {{ adminName }}
                        <el-avatar :src="circleUrl" size="small"></el-avatar>
                        <span>个人中心</span>
                    </template>
                    <el-menu-item index="5-1">选项1</el-menu-item>
                    <el-menu-item index="5-2">选项2</el-menu-item>
                    <el-menu-item index="5-3" @click="handleLogout">退出登陆</el-menu-item>
                </el-submenu>
            </el-col>
        </el-row>
    </el-menu>
</template>
<script>
import { logout } from "@/api/adminApi";
import { toLogin } from "@/api/index";
const options = {
    data() {
        return {
            circleUrl: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
            adminName: ""
        }
    },
    methods: {
        handleSelect() {

        },
        init() {
            let adminInfo = JSON.parse(localStorage.getItem("admin"));
            if (adminInfo == null) toLogin();
            else { this.adminName = adminInfo.adminName ?? "admin" }
        },
        handleLogout() {
            // console.log("退出登录");
            this.$confirm("确认退出登录？", "退出登录")
                .then(() => {
                    localStorage.removeItem("admin");
                    logout();
                    toLogin();
                }).catch(() => { })
        }
    },
    components: {

    },
    computed: {

    },
    created() {
        this.init();
    }
}
export default options;
</script>
<style>

</style>